home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-14 | 3.6 KB | 152 lines | [TEXT/MPS ] |
- /* _________________________________________________________________________________________________________ //
- Copyright © 1993 Apple Computer, Inc. All rights reserved.
- Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
- Programmer: Kent Sandvik
- Date: 1/2/93
- Revision comments are at the end of this file.
- ---
- TMemory is a simple object checks heap and stack values, as well as changes them.
- TMemoryClass.cp contains the TMemory member function definitions.
- _________________________________________________________________________________________________________ */
-
- #ifndef _MEMORYCLASS_
- #include "MemoryClass.h"
- #endif
-
-
- // CONSTRUCTORS AND DESTRUCTORS
- #pragma segment Memory
- TMemory::TMemory(const long minHeap,
- const long minStack)
- // The one and only constructor, takes min values for stack and heap if wanted, but
- // these are not needed.
- {
- fMinHeap = minHeap; // minimum heap size
- fMinStack = minStack; // minimum stack size
- }
-
-
- #pragma segment Memory
- TMemory::~TMemory()
- // Default constructor -- unused for the time being.
- {
- }
-
-
- // MAIN INTERFACE
- #pragma segment Memory
- long TMemory::GetStackSize()
- // Get size of the current stack.
- {
- return ::StackSpace(); // return size of stack
- }
-
-
- #pragma segment Memory
- Boolean TMemory::SetStackSize(const long stackValue)
- // Set absolute size of current stack.
- {
- long oldValue = ::StackSpace();
-
- // Set the new value
- SetApplLimit((Ptr)((long)GetApplLimit() - (stackValue - oldValue)));
-
- fError = MemError();
- VASSERT(fError == noErr, ("Problems with SetApplLimit = %d", fError));
-
- if (fError != noErr)
- return false;
- else
- return true;
- }
-
-
- #pragma segment Memory
- Boolean TMemory::SetStackSizeFromResources()
- // Get stack values from pre-defined resource (that should be part of the application).
- {
- long newStackSize = 0;
-
- short num = ::CountResources(kStackResource);// find out how many we got
- if (num == 0) // none?
- goto FromResourceFalse;
- else
- {
- for (int i = 1; i <= num; ++i)
- {
- Handle temp = ::GetIndResource(kStackResource, i);
- fError = ResError();
- VASSERT(fError == noErr, ("Problems with GetIndResource = %d", fError));
- {
- const StackResource& stackValueH = **((StackValueHandle)temp);
- newStackSize += stackValueH.stackVal;
- }
- if (temp != NULL)
- ::ReleaseResource(temp);
- }
- }
- this->SetStackSize(newStackSize); // set the new stack size
- return true;
-
- FromResourceFalse:return false;
- }
-
-
- #pragma segment Memory
- Boolean TMemory::IncreaseStackSize(const long stackValue)
- // Increase the stack value from the current size.
- {
- ::SetApplLimit((Ptr)((long)GetApplLimit() - stackValue));
-
- fError = MemError();
- VASSERT(fError == noErr, ("Problems with SetApplLimit = %d", fError));
-
- if (fError != noErr)
- return false;
- else
- return true;
- }
-
-
- #pragma segment Memory
- Boolean TMemory::CheckStackSize()
- // Check if we hit the low watermark of the stack size.
- {
- long currentStack = ::StackSpace();
-
- if (currentStack < fMinStack)
- return false;
- else
- return true;
- }
-
-
- #pragma segment Memory
- Boolean TMemory::CheckHeapSize()
- // Check if we hit the low watermark of the heap size.
- {
- long currentHeap = this->GetHeapSize();
-
- if (currentHeap < fMinHeap)
- return false;
- else
- return true;
- }
-
-
- #pragma segment Memory
- long TMemory::GetHeapSize()
- // Get size of current heap.
- {
- return ((long)GetApplLimit() - (long)ApplicZone());
- }
-
-
- // _________________________________________________________________________________________________________ //
-
- /* Change History (most recent last):
- No Init. Date Comment
- 1 khs 1/2/93 New file
- 2 khs 1/3/93 Cleanup
- */
-